package com.sc.nft.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.dao.MallOrderReconsiderDao;
import com.sc.nft.entity.MallOrderReconsider;
import com.sc.nft.entity.dto.MallOrderReconsiderAdminDetailDTO;
import com.sc.nft.entity.dto.MallOrderReconsiderAdminPageDTO;
import com.sc.nft.entity.vo.AuditMallOrderReconsiderVO;
import com.sc.nft.entity.vo.MallOrderReconsiderAdminPageVO;
import com.sc.nft.enums.MallOrderReconsiderEnum;
import com.sc.nft.exception.GlobalRunTimeException;
import com.sc.nft.service.MallOrderReconsiderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 * 订单复议记录 服务实现类
 * </p>
 *
 * @author ligen
 * @since 2024-01-17
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class MallOrderReconsiderServiceImpl implements MallOrderReconsiderService {

    private final MallOrderReconsiderDao mallOrderReconsiderDao;

    /**
     * 订单复议列表
     *
     * @param mallOrderReconsiderAdminPageVO
     * @return
     */
    @Override
    public Page<MallOrderReconsiderAdminPageDTO> getPage(MallOrderReconsiderAdminPageVO mallOrderReconsiderAdminPageVO) {
        return mallOrderReconsiderDao.getPage(mallOrderReconsiderAdminPageVO.getPageNo(), mallOrderReconsiderAdminPageVO.getPageSize(), mallOrderReconsiderAdminPageVO.getDaoId(), mallOrderReconsiderAdminPageVO.getStartTime(), mallOrderReconsiderAdminPageVO.getEndTime(), mallOrderReconsiderAdminPageVO.getOrderNo());
    }

    /**
     * 获取订单复议详情
     *
     * @param id
     * @return
     */
    @Override
    public MallOrderReconsiderAdminDetailDTO getDetail(Long id) {
        return mallOrderReconsiderDao.getDetail(id);
    }

    @Override
    public MallOrderReconsider getById(Long id) {
        return mallOrderReconsiderDao.getById(id);
    }

    /**
     * 订单复议审核
     *
     * @param auditMallOrderReconsiderVO
     */
    @Override
    public void audit(Long sysMemberId, AuditMallOrderReconsiderVO auditMallOrderReconsiderVO) {
        MallOrderReconsider mallOrderReconsider = getById(auditMallOrderReconsiderVO.getId());
        if (Objects.isNull(mallOrderReconsider)) {
            throw new GlobalRunTimeException("订单复议不存在");
        }
        if (MallOrderReconsiderEnum.UNDER_RECONSIDERATION == mallOrderReconsider.getStatus()){
            mallOrderReconsider.setStatus(auditMallOrderReconsiderVO.getStatus());
            mallOrderReconsider.setAuditId(sysMemberId);
            mallOrderReconsider.setRemark(auditMallOrderReconsiderVO.getRemark());
            mallOrderReconsider.updateById();
        }
    }
}
